

var CHART_SOURCES = [
"YAHOO_REUTERS",
"STOCK_REUTERS"
];

var CHART_SOURCES_Url = [
"http://yahoo.reuters.com/stocks/ChartResize.aspx",
"http://stocks.us.reuters.com/"
];

var CHART_LOADING_TYPE = [
"SYNCHRONOUS",
"ASYNCHRONOUS"
];

var CHART_FUNCTION =[
getYahooReutersChartUrl,
getStockReutersChartUrl
];

var ZOOM_HEADER = [
[[1,"day","Today"],
[3,"day","3d"],
[1,"week","1w"],
[2,"week","2w"],
[1,"month","1m"],
[2,"month","2m"],
[6,"month","6m"],
[1,"year","1y"],
[2,"year","2y"]],

[[1,"day","Today"],
[5,"day","5d"],
[10,"day","10d"],
[1,"month","1m"],
[6,"month","6m"],
[1,"year","1y"],
[3,"year","3y"]]
];



function setChartZoomHeader(_moduleId,_tableId,_headerConf,_currentDuration, _currentUnit)
{

	var table = _gel(_tableId+'_zoom');
	var contentChart = "";
	var zoom_cell;
	//var today_cell;

	zoom_cell = table.rows[0].cells[0];
	//today_cell= table.rows[0].cells[1];;


	contentChart += '<b>Zoom:</b> ';

	for(var i=0;i<_headerConf.length;i++)
	{
		if(_currentDuration== _headerConf[i][0] && _currentUnit== _headerConf[i][1])
			contentChart += _headerConf[i][2]+' ';
		else
			contentChart += '<a href ="#" onClick="updateChartPreferences'+_moduleId+'('+_headerConf[i][0]+',\''+_headerConf[i][1]+'\')">'+_headerConf[i][2]+'</a> ';
	}



	zoom_cell.innerHTML = contentChart;
	//today_cell.innerHTML = '<font size=2><b>Today:</b> '+getDateAsString(new Date())+'</font>';

}



function getYahooReutersChartUrl(_conf, _quoteSymbol)
{

	return _conf.chartUrl+'?symbol='+_quoteSymbol+'&frequency=1day&duration='+_conf.chart_timeDuration+_conf.chart_timeUnit+'&width=250';
}

function getStockReutersChartUrl(_conf, _quoteSymbol, _quoteStockExchange)
{
	var chartUrl = _conf.chartUrl+"buffer/chartAdvancedBuffer.asp?cht=/reuters/us/research/advanced.cht";

	var timeFrame = _conf.chart_timeDuration;
	if(_conf.chart_timeUnit == 'day')
	{
		timeFrame *= 1;
	}
	else if(_conf.chart_timeUnit == 'week')
	{
		timeFrame *= 7;
	}
	else if(_conf.chart_timeUnit == 'month')
	{
		timeFrame *= 30;
	}
	else if(_conf.chart_timeUnit == 'year')
	{
		timeFrame *= 365;
	}

	var symbol = getStockExchangeAbbreviation(_quoteStockExchange)+';'+_quoteSymbol.substring(0,4);

	var aux = chartUrl+'&symbol='+symbol+'&timeFrame='+timeFrame+'&width=260&height=210';

	return aux;
}

function getChartId(module,quote,id)
{
	return 'chart_'+module.id+'_'+id+'_'+quote.symbol;
}

function getChartTabTemplate(_prefs,_tabId, _class, _id, _urlSource)
{

	var contentChart = '';


	contentChart = '<div class="'+_class+'" id="'+_tabId+'">';
	contentChart += '<table border="0" cellpadding="2" cellspacing="0" width="100%">';
	contentChart += '<table id="'+_tabId+'_zoom">';
	contentChart += '<tr class="chart_legend">';
	contentChart += '<td align="right"></td>';
	contentChart += '</tr></table>';
	contentChart += '<table border="0" cellpadding="2" cellspacing="0" width="100%">';
	contentChart += '<tr class="head">';
	contentChart += '<td align="center"><span id="'+_tabId+'_name"><span class="loading">Loading...</span></span></td>';
	contentChart += '<td>(<span id="'+_tabId+'_link"><span class="loading">Loading...</span></span>)</td>';
	contentChart += '</tr></table>';
	contentChart +='<table align=center style="border:0;font-size: 8pt;font-family: Tahoma" width="100%" id="contentTable" cellspacing=0 cellpadding=2>';
	contentChart +='<tr>';
	contentChart +='<td align="center" title="Chart: '+_id+'"><span id="'+_tabId+'_chart"><span class="loading">Loading...</span><span></td></tr>';
	contentChart +='</table>';
	contentChart += '<table>';

	var sourceStr;
	var init;
	var end;

	init = _urlSource.indexOf('//');
	if (init==-1) init =0;
	else
	 init +=2;
	sourceStr = _urlSource.substring(init,_urlSource.length);

	end = sourceStr.indexOf('/');
	if (end==-1) end =sourceStr.length;
	else
	 init +=1;
	sourceStr = sourceStr.substring(0,end);


	contentChart += '<tr class="chart_legend"><td> Source: '+sourceStr;
	contentChart += '</td></tr>';
	contentChart += '</table>';
	contentChart +='</div>';

	return contentChart;
}


function updateChartPreferences(_pref,_timeDuration,_timeUnit, _updateChartFunction)
{
	_updateChartFunction();
}


function setChartTabValue(_id,_quote, _quoteUrl, _chartUrl)
{
	var tabId = _id;

	var spanName= _gel(tabId+'_name');
	var spanLink = _gel(tabId+'_link');
	var spanChart = _gel(tabId+'_chart');

	spanName.innerHTML= _quote.name;
	spanLink.innerHTML= '<a href="'+_quoteUrl+'" target="blank">'+_quote.alias+' / '+_quote.symbol+'</a>';
	spanChart.innerHTML= '<img src="'+_chartUrl+'"></td>';

}


